package com.ftwj.demo.scheduler;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.PersistJobDataAfterExecution;
import org.springframework.scheduling.quartz.QuartzJobBean;

import com.ftwj.demo.utils.logs.LoggerUtil;

@PersistJobDataAfterExecution   //保存在JobDataMap传递的参数
@DisallowConcurrentExecution   //保证多个任务间不会同时执行.所以在多任务执行时最好加上
public class PrintWordsJob extends QuartzJobBean{

	@Override
    public void executeInternal(JobExecutionContext context) throws JobExecutionException {
    	String printTime = new SimpleDateFormat("yy-MM-dd HH-mm-ss").format(new Date());
    	JobDataMap map = context.getMergedJobDataMap();
    	start(map.getString("str"),map.getInt("num"));
    	LoggerUtil.info("【{}】定时任务已执行，当前时间:{}",context.getJobDetail().getKey(),printTime);
	}
	
	
	public void start(String str,int num) {
		LoggerUtil.info("此处模拟实现了一个定时任务，传入参数：程序员【{}】提醒您多喝热水，每小时【{}】次！",str,num);
	}
	
}